package ui.robots_wicket;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PropertyListView;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;

import unq.uis.robots.applicationsModels.JugadorVista;
import unq.uis.robots.model.Robot;

/**
 * @author leo
 */
public class MainPage extends WebPage {
	private static final long serialVersionUID = 1L;
	private JugadorVista jugadorVista;	

	public MainPage(JugadorVista jugadorVista) {
		super(new CompoundPropertyModel<JugadorVista>(jugadorVista));
		this.jugadorVista = jugadorVista;
		this.agregarLabels();				
		this.agregarTablaMisRobots();
		this.agregarTablaContrincantes();
		this.agregarLinks();
		this.add(new FeedbackPanel("feedbackPanel"));
	}

	public void agregarLabels(){
		this.add(new Label("nombre"));
		this.add(new Label("dinero"));
	}

	public void agregarTablaMisRobots(){
		this.add(new PropertyListView<Robot>("robots") {
			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(ListItem<Robot> item) {				
				item.add(new Label("nombre"));
				item.add(new Label("poderTotal"));
				item.add(new Label("danio"));
				
				final Robot robot = item.getModelObject();
				item.add(new Link<String>("reparar"){
					private static final long serialVersionUID = 1L;

					public void onClick() {
						this.setResponsePage(new RepararPage(this.getPage(), robot));
					};
				}
				);
				
				item.add(new Link<String>("mejorar"){
					private static final long serialVersionUID = 1L;

					public void onClick() {
						this.setResponsePage(new MejorarPage(this.getPage(), MainPage.this.jugadorVista, robot));
					};
				}
				);
				
				item.add(new Link<String>("vender"){
					private static final long serialVersionUID = 1L;

					public void onClick() {
						this.setResponsePage(new VenderPage(this.getPage(), robot));
					};
				}
				);
				
				item.add(new Link<String>("competir"){
					private static final long serialVersionUID = 1L;

					public void onClick() {
						this.setResponsePage(new ElegirContrincantePage(this.getPage(),robot));
					};	
				}
		);
			};
	});
	}
	
	public void agregarTablaContrincantes() {
		PropertyListView<Robot> otrosRobots = new PropertyListView<Robot>("otrosRobots") {
			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(ListItem<Robot> item) {
				item.add(new Label("nombre"));
				item.add(new Label("duenio"));
				item.add(new Label("poderTotal"));
				item.add(new Label("danio"));		
			}			
		};
		this.add(otrosRobots);
	}
	
	private void agregarLinks() {
		this.add(new Link<String>("comprar"){
			private static final long serialVersionUID = 1L;

			public void onClick() {
				this.setResponsePage(new ComprarPage(this.getPage(), MainPage.this.jugadorVista));
			};
		}
		);
	}
	
}